var app = getApp();
var $ = require("../../utils/httpHelper.js")
var QQMapWX = require('../../utils/qqmap-wx-jssdk.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    name: '',
    height: 0,
    width: 0,
    isOver: true,
    topimgh: 0,
    city:'全部',
    page:1,
    pagesize:10,
    totalpage:1,
    province_id:0,
    nomore: true,
    banner:[]
  },
  onShareAppMessage: function (res) {
    app.shareApp(res)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var self = this;
    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        self.setData({
          height: res.windowHeight,
          width: res.windowWidth
        })
      }
    })
    if (!app.check_empty(options.id) && !app.check_empty(options.name)) {
      this.setData({
        province_id: options.id
      })
    }
    let params = {
      rd_session: app.globalData.userInfo.rd_session,
      province_id: this.data.province_id,
      page: this.data.page,
      page_size: this.data.pagesize
    }
    $.httpPost("mendian_list", params, (data, err) => {
      this.setData({
        list: data.list,
        city: options.name,
        totalpage: data.total_page,
        banner:data.data.banner,
        province_id: options.id
      })
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    console.log("xila")
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  toxq(e) {
    let id = e.currentTarget.dataset.id
    let name = e.currentTarget.dataset.name
    wx.navigateTo({
      url: '../../pages/yeni/plxq?id=' + id + "&name=" + name,
    })
  },
  callphone(e) {
    let num = e.currentTarget.dataset.num
    wx.makePhoneCall({
      phoneNumber: num
    })
  },
  imageLoad: function (e) {
    let that = this
    this.setData({
      topimgh: app.fixImgW(e, that.data.width),
    })
  },

  //滑动到底部 上拉加载
  scrollBottom: function () {
    this.data.page++
    if (this.data.page > this.data.totalpage) {
      this.setData({
        nomore: false
      })
    } else {
      let params = {
        rd_session: app.globalData.userInfo.rd_session,
        province_id: this.data.province_id,
        page: this.data.page,
        page_size: this.data.pagesize
      }
      $.httpPost("mendian_list", params, (data, err) => {
        let arr = this.data.objarr;
        for (let item of data.list) {
          arr.push(item);
        }
        this.setData({
          objarr: arr
        })
      })


    }

  },

})